<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">

        <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

        <title>粉粉管理系统</title>

        <!-- Bootstrap core CSS -->
        <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
        <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

        <!--Animation css-->
        <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

        <!--Icon-fonts css-->
        <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
        <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />
        
        <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">
        
        <!-- Plugins css -->
        <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

        <!-- DataTables -->
        <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />

        <!-- Custom styles for this template -->
        <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
        <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">
        
        <!-- My styles for this template -->
        <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">

    </head>

    <body>

        <!-- Aside Start-->
        <!--{template admin_v2/leftside}-->
        <!-- Aside Ends-->


        <!--Main Content Start -->
        <section class="content">
            
            <!-- Header -->
            <!--{template admin_v2/header}-->
            <!-- Header Ends -->


            <!-- Page Content Start -->
            <!-- ================== -->

            <div class="wraper container-fluid diary-topics">
            
            	<div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">点滴话题列表</h3>
                            </div>
                            <div class="panel-body">
                            	<div class="row">
                                	<div class="col-md-5 col-sm-5 col-xs-5">
	                                	<!-- Search -->
									    <form class="form-inline" role="form" action="admin.php?ac=diarytopic_class&op=searchDiaryTopic" method="post" style="float:left;">
		                                    <div class="form-group">
		                                        <input type="text" class="form-control"  placeholder="输入话题名称" name="name">
		                                    </div>
		                                    <button type="submit" class="btn btn-success m-l-10">点击搜索</button>
											<button class="btn btn-info myFlushCache m-l-10">刷新缓存</button>
											<button class="btn btn-info updateHotDiary m-l-10">刷新话题下热门点滴缓存</button>
		                                </form>
		                            </div>
                            	</div>
                                <div class="row">
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <table id="datatable" class="table table-striped table-bordered">
                                            <thead>
                                                <tr>
                                                    <th>话题id</th>
				                                    <th>名称</th>
				                                    <th>创建者</th>
				                                    <th>热度值</th>
				                                    <th>类型</th>
				                                    <th>状态</th>
				                                    <th>操作</th>
                                                </tr>
                                            </thead>

                                            <tbody>
                                            	<!--{loop $list $topic}-->
                                                <tr>
                                                    <td>$topic['id']</td>
				                                    <td><a href="admin.php?ac=diarytopic_class&op=getDiarysByTopic&gid={$topic['id']}" class="btn btn-primary btn-xs m-b-5 topic-name" target="_blank"># $topic['name']</a></td>
				                                    <td><a href="admin.php?ac=admin&do=accountOperation&uid=$topic['user']['uid']"  class="btn btn-info btn-xs m-b-5" target="_blank">$topic['user']['nickname']</a></td>
				                                    <td>$topic['hot']</td>
				                                    <td>
				                                    	<!--{if $topic['type'] == 0}-->
						                            		<span class="label label-info">普通</span>
						                            	<!--{else}-->
						                            		<span class="label label-warning">热门</span>
						                            	<!--{/if}-->
				                                    </td>
				                                    <td>
				                                    	<!--{if $topic['status'] == 3}-->
															<span class="label label-danger">已删除</span>
														<!--{else}-->
															<span class="label label-pink">正常</span>
														<!--{/if}-->
														<!--{if $topic['recommend'] != 0}-->
														<span class="label label-danger">推荐</span>
														<!--{/if}-->
				                                    </td>
				                                    <td class="actions" data-gid="$topic['id']" data-type="$topic['type']">
				                                    	<a href="#" class="on-default edit-row btn btn-default btn-sm topicinfo" data-toggle="modal" data-target="#con-close-modal"><i class="fa fa-pencil"></i></a>
				                                        <a href="#" class="on-default remove-row btn btn-default btn-sm"><i class="fa fa-trash-o"></i></a>
				                                    </td>
                                                </tr>
                                                <!--{/loop}-->
                                             </tbody>
                                         </table>
                                         <!--{if $pageUrl}-->
		                                 <ul class="pager"> 
		                                    <li> 
		                                        <a href="{$pageUrl['prev']}"> <i class="fa fa-angle-double-left"></i>上一页</a> 
		                                    </li> 
		                                    <li> 
		                                        <a href="{$pageUrl['first']}"> <i class="fa"></i>第一页</a> 
		                                    </li> 
		                                    <li> 
		                                        <a href="{$pageUrl['next']}">下一页 <i class="fa fa-angle-double-right"></i> </a> 
		                                    </li> 
		                                 </ul>
		                                 <!--{/if}--> 
                                     </div>
                                 </div>
                             </div>
                         </div>
                     </div>
                 </div>

            </div>
            <!-- Page Content Ends -->
            <!-- ================== -->
            
            <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
      
  			</div><!-- /.modal -->
            

            <!-- Footer Start -->
            <!--{template admin_v2/footer}-->
            <!-- Footer Ends -->



        </section>
        <!-- Main Content Ends -->


        <!-- js placed at the end of the document so the pages load faster -->
        <script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>

		<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>

        <script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>
        
        <!-- Modal-Effect -->
        <script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>
        
		<script type="text/javascript">
            $(document).ready(function() {
            	// 设置table配置
                $('#datatable').dataTable({
                	"iDisplayLength": 50,
                	"aLengthMenu": [10, 20, 50, 100],
                	"searching": false,
                	"bLengthChange" : false,
                	"bSort" : true,
                	"bPaginate": false,
					"aaSorting": [
						[ 3, "desc" ]
					]
                });
				
				$('.myFlushCache').click(function () {
					swal(
							{
								title: "确定刷新缓存?",
								text: "当手动调整了热门需要立即生效时执行此操作",
								type: "warning",
								showCancelButton: true,
								confirmButtonColor: "#DD6B55",
								confirmButtonText: "确定",
								cancelButtonText: "取消",
								closeOnConfirm: false
							},
							function(){
								$.post(
										"admin.php?ac=diarytopic_class&op=flushDiaryTopicHotCache",
										{},
										function (r) {
											swal("刷新成功!", "操作已经执行，请查看效果~~", "success");
										}
								);
							});
					return false;
				})
                $('.updateHotDiary').click(function () {
					swal(
							{
								title: "确定刷新缓存?",
								text: "执行此操作将更新每个话题下的热门点滴，手动设置的热门将被抛弃",
								type: "warning",
								showCancelButton: true,
								confirmButtonColor: "#DD6B55",
								confirmButtonText: "确定",
								cancelButtonText: "取消",
								closeOnConfirm: false
							},
							function(){
								$.post(
										"admin.php?ac=diarytopic_class&op=updateHotDiary",
										{},
										function (r) {
											swal("刷新成功!", "操作已经执行，请查看效果~~", "success");
										}
								);
							});
					return false;
				})
                
                // 删除点滴话题
                $(".remove-row").click(function() {
                	var topic = $(this).parent().data();
                	var gid   = topic.gid;
                	var type  = topic.type;

                	swal(
                		{   
	                		title: "确定删除?",
	                		text: "被删除话题可以被恢复，但也要慎重操作!",
	                		type: "warning",   
	                		showCancelButton: true,   
	                		confirmButtonColor: "#DD6B55",   
	                		confirmButtonText: "Sure!",   
	                		closeOnConfirm: false 
                		}, 
                		function(){
                			$.ajax(
                		            {
                		                url     :   "admin.php?ac=diarytopic_class&op=deleteDiaryTopic",
                		                type    :   "POST",
                		                data    :   {gid : gid, type : type},
                		                success :   function(data)
                		                            {
                		                				if (data) {
                		                					swal("删除成功!", "该非法话题已被管理员删除！", "success");
                		                				}else{
                		                					swal("删除失败!", "该非法话题删除出现了问题！", "error"); 
                		                				}
                		                				refresh();
                		                            }
                		            });
                		});
                });
                
             	// 获取点滴话题详情
                $(".topicinfo").click(function() {
                	var topic = $(this).parent().data();
                	var gid   = topic.gid;

            		$.ajax(
        		            {
        		                url     :   "admin.php?ac=diarytopic_class&op=getDiaryTopicInfo",
        		                type    :   "POST",
        		                data    :   {gid : gid},
        		                success :   function(data)
        		                            {
        		                				$("#con-close-modal").empty();
        		                				$("#con-close-modal").append(data); 
        		                            }
        		            });
           		});
             	
             	// 编辑话题信息
                $(document).on("click",".edittopic",function(){
                	var param   =   $(".modal-content > form").serialize();
                	console.log(param);
                    $.ajax(
                    {
                        url     :   "admin.php?ac=diarytopic_class&op=editDiaryTopicInfo",
                        type    :   "POST",
                        data    :   param,
                        success :   function(data)
                                    {
                        				if (data) {
		                					swal("编辑成功!", "该话题已经被成功编辑！", "success");
		                				}else{
		                					swal("编辑失败!", "编辑该话题时出现了问题！", "error"); 
		                				}
	                					refresh();
                                    }
                    });
                });
				
             	// 刷新当前页面
        		function refresh(){
        		    setInterval(window.location.reload(),5000);
        		}
            } );
        </script>
    </body>
</html>
